package com.hccake.ballcat.codegen.util;

import com.alibaba.fastjson.JSON;
import com.hccake.ballcat.codegen.model.dto.ExecSqlDTO;
import com.hccake.ballcat.codegen.model.vo.ExecSqlVO;

import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;

/**
 * @author ccd
 * @Desc
 * @date 2024/12/19 8:56
 */
public class TestUatil {

	/*
	 * public static void main(String[] args) { // 昨天零点时间 String[] mm =
	 * "fd,fd".split(","); System.out.println(mm);
	 *
	 * }
	 */

	public static void main1(String[] args) {
		// 配置邮件会话属性
		Properties properties = new Properties();
		properties.put("mail.smtp.host", "smtp.exmail.qq.com");
		properties.put("mail.smtp.port", "465");
		properties.put("mail.smtp.auth", "true");
		properties.put("mail.smtp.ssl.enable", "true");

		// 创建邮件会话
		Session session = Session.getInstance(properties, new javax.mail.Authenticator() {
			protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
				return new javax.mail.PasswordAuthentication("cheng_cd@murongtech.com", "evgiqDLMDHMX9Mhq");
			}
		});
		try {
			// 创建邮件消息对象
			MimeMessage message = new MimeMessage(session);
			// 设置发件人
			message.setFrom(new InternetAddress("cheng_cd@murongtech.com"));
			// 设置收件人
			message.addRecipient(MimeMessage.RecipientType.TO, new InternetAddress("cheng_cd@murongtech.com"));
			// 设置邮件主题
			message.setSubject("邮件主题");
			StringBuffer sbf = new StringBuffer();
			sbf.append("<b><p><font color='red' size='5'>&nbsp;&nbsp;&nbsp;构建结果：构建失败</font> </p></b>");
			sbf.append("<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;执行结果信息：" + JSON.toJSONString(new ExecSqlVO()) + " </p>");
			sbf.append("<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sql执行信息：" + JSON.toJSONString(new ExecSqlDTO()) + " </p>");
			// 设置邮件正文 <p ><span style=\"font-size:20.0pt\">")
			message.setContent(sbf.toString(), "text/html;charset=utf-8");
			// 发送邮件
			Transport.send(message);
			System.out.println("邮件发送成功");
		}
		catch (Exception e) {
			System.out.println("邮件发送失败");
			e.printStackTrace();
		}
	}

}
